package com.ruoyi.system.support;   //修改包路径

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.Response;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hikvision.artemis.sdk.constant.Constants;
import com.hikvision.artemis.sdk.constant.SystemHeader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import static com.hikvision.artemis.sdk.util.HttpUtil.wrapClient;

/**
 * 海康威视接口调用支持类
 * artemis接口调用
 * @Params
 * @Return
 * @Description
 * @Throws
 * @email 610207151@qq.com
 * @Author Liuwq -FUSE
 * @Date 2025/11/07
 */
@Service
public class ArtemisPostSupport {
	private static final String ARTEMIS_PATH = "/artemis";
	/**
	 * 根据需求调整超时时间
	 */
	static {
		//连接超时时间
		Constants.DEFAULT_TIMEOUT = 10000;
		//读取超时时间
		Constants.SOCKET_TIMEOUT = 60000;
	}

	/**
	 * 查询访客来访记录v2
	 * @Params
	 * @Return @return {@link String }
	 * @Description
	 * @Throws @throws Exception
	 * @Author Liuwq
	 * @Date 2025/11/07
	 */
	//@Scheduled(cron = "1/5 * * * * *")
	public String callPostApiGetFKList() throws Exception {
		/**
		 * 查询访客来访记录v2
		 */
		ArtemisConfig config = new ArtemisConfig();
		config.setHost("127.0.0.1"); // 平台nginx所在ip及https对应端口号
		config.setAppKey("20469790");  // 秘钥appkey
		config.setAppSecret("lofnD6DbnBllHmk5YOyx");// 秘钥appSecret
		final String getCamsApi = ARTEMIS_PATH + "/api/visitor/v2/visiting/records";
		Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
		paramMap.put("pageNo", "1");
		paramMap.put("pageSize", "1000");
		String body = JSON.toJSON(paramMap).toString();
		Map<String, String> path = new HashMap<String, String>(2) {
			{
				put("https://", getCamsApi);
			}
		};
		return ArtemisHttpUtil.doPostStringArtemis(config,path, body, null, null, "application/json");
	}


	public String callPostApiGetMJList() throws Exception {
		/**
		 * 查询访客来访记录v2
		 */
		ArtemisConfig config = new ArtemisConfig();
		config.setHost("127.0.0.1"); // 平台nginx所在ip及https对应端口号
		config.setAppKey("20469790");  // 秘钥appkey
		config.setAppSecret("lofnD6DbnBllHmk5YOyx");// 秘钥appSecret
		final String getCamsApi = ARTEMIS_PATH + "/api/acs/v2/door/events";
		Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
		paramMap.put("pageNo", "1");
		paramMap.put("pageSize", "1000");
		String body = JSON.toJSON(paramMap).toString();
		Map<String, String> path = new HashMap<String, String>(2) {
			{
				put("https://", getCamsApi);
			}
		};
		return ArtemisHttpUtil.doPostStringArtemis(config,path, body, null, null, "application/json");
	}

}
